package com.train.ticket.facade.web;

import cn.hutool.core.bean.BeanUtil;
import com.train.common.resp.CommonResp;
import com.train.common.resp.PageResp;
import com.train.common.utils.helper.UserHelper;
import com.train.dto.TicketPageDTO;
import com.train.req.TicketPageReq;
import com.train.resp.TicketPageResp;
import com.train.ticket.service.TicketService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ticket Facade 接口
 * @author baitiaojun
 * @createDate 2025-03-14 15:17:16
 */
@RestController("webTicketFacade")
@RequiredArgsConstructor
@RequestMapping("ticket")
public class TicketFacade {

    private final TicketService ticketService;

    @PostMapping("page")
    CommonResp pageList(@RequestBody @Validated TicketPageReq req) {
        TicketPageDTO ticketPageDTO = BeanUtil.copyProperties(req, TicketPageDTO.class);
        ticketPageDTO.setMemberId(UserHelper.getUserId());
        PageResp<TicketPageResp> pageResp = ticketService.pageList(ticketPageDTO);
        return CommonResp.ok(pageResp);
    }
}
